<!DOCTYPE html>
<html style="height: 100%" xmlns="http://www.w3.org/1999/html">
    <head>

        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <title>出库单打印</title>
        <link rel="shortcut icon" href="/web/static/src/img/favicon.ico" type="image/x-icon">
        <link rel="stylesheet" href="/web/static/src/css/full.css">
        <link rel="stylesheet" href="/web/static/lib/fontawesome/css/font-awesome.css">
        <link rel="stylesheet" href="/web/static/lib/bootstrap/css/bootstrap.css">
        <link rel="stylesheet" href="/web/static/src/css/base.css">

        <script src='http://192.168.0.10/CLodopfuncs.js'></script>
        <script language="javascript" src="/lodop/static/src/js/mathlibrary.js"></script>

        <style type="text/css" id="style">
            body{padding: 10px; font-size: 10pt; overflow: auto}

            @media print
            {
                .print-hide {display:none}
            }

            .td_inline {
                display:block;
                overflow:hidden;
                white-space:nowrap;
                text-overflow:ellipsis;
                width: 370pt;
            }

            .nowrap{
                white-space:nowrap;
            }
            /*.table td.noborder{*/
            /*border-top: 0px;*/
            /*}*/

            .table thead tr td{font-weight: bold; font-size: 11pt}

            h4{margin: 0px;  padding: 0px;font-size: 14pt}

            h5{
                font-size:11pt; font-family:'黑体'; font-weight: bold; margin: 0px;  padding: 0px;
            }

            div{font-size: 10pt}

            span.foot_sign{border-bottom: 1px solid #ddd}

            .table tbody tr td{border-top: 1px solid #ddd;}
            .table tbody tr:last-child td{border-top: 1px solid #fff; padding: 0px}
            .table tbody tr.memo td {padding:0px; border-top:0px}

            td{font-size:10pt}

            .font-middle{
                font-size: 12pt;
            }


            .page_head{
                padding-bottom: 20px;
            }

            .underline{text-decoration: underline;}
        </style>
    </head>

    <body>
    {%if ids|length == 0 %}
    参数错误
    {%elif ids|length == 1 %}

    <div class="controls controls-row print-hide">
        <script>
        function LICENSES() {
            LODOP.SET_LICENSES("","CD9A14E608164F55F35D564059E8F43B","C94CEE276DB2187AE6B65D56B3FC2848","15F0BE661E7532B77491843CB2ED09AD");
        };

        function print_preview(){
            if (!LODOP.VERSION) return;
            LODOP.PRINT_INIT("东方团购中心出货单{{order.name}}");
    		LODOP.SET_PRINT_PAGESIZE(1, 1910, 2795, "1910x2795"); //2799的时候打5到8页会出现一行的向下偏移, 2795时目测还少走一点点1毫米左右吧, 2796时打15张后向下偏1行

            var printer_count = LODOP.GET_PRINTER_COUNT();
            var intPrinterIndex = -1;
            for (var i = 0; i < printer_count; i ++){
                if(LODOP.GET_PRINTER_NAME(i).indexOf('东方团购中心出货单') >= 0){
                    intPrinterIndex = i;
                    break;
                }
            }
            if (intPrinterIndex == -1){
                alert('东方团购中心出货单打印机不存在，无法打印');
                return;
            }
            CreateOneFormPage1();
            if (LODOP.SET_PRINTER_INDEXA(intPrinterIndex+'')){
                LODOP.PRINT();
                document.getElementById('btn-print').innerHTML = "已经打印";
                document.getElementById('btn-print').className = "btn btn-primary disabled";
            }
        }
        window.onload = function(){
            var xiaoxie = document.getElementById('spanGrandTotal').innerHTML;
            var daxie = cmycurd(xiaoxie);
            document.getElementById('spanGrandTotal').innerHTML = xiaoxie + " (" + daxie + ")";
            LICENSES();
            //如果存在父级，则自动打印
            if (parent.batch_print_next){
                document.getElementById('btn-print').innerHTML = "自动打印模式";
                document.getElementById('btn-print').className = "btn btn-primary disabled";
                setTimeout(function(){
                    print_preview();
                    setTimeout(function(){
                        parent.batch_print_next();
                    }, 1000)
                }, 2000)
            }
        }


    function CreateOneFormPage1(){
        LODOP.ADD_PRINT_SETUP_BKIMG("<img border='0' src='/dftg_lodop/static/src/img/stock_picking_bg.png'>");
        LODOP.SET_SHOW_MODE("BKIMG_IN_PREVIEW", 1);
{% for order_line in order.order_line %}
    {% if loop.index0%10==0 %}
        LODOP.NewPage();
        {%  if is_vip %}
        LODOP.ADD_PRINT_TEXT(225,80,150,16,"VIP");
        {% endif %}
        LODOP.ADD_PRINT_TEXT(270,105,270,16,"{{order.partner_id.name|default('',True)}}");
        LODOP.SET_PRINT_STYLEA(0,"Horient",3);
        LODOP.ADD_PRINT_TEXT(266, 400, 154,30,"{% if order.real_so_id %}{{ order.real_so_id.name }}{% else %}{{ order.name }}{% endif%}");
        LODOP.SET_PRINT_STYLEA(0,"FontSize",12);
        LODOP.ADD_PRINT_TEXT(294,105,90,16,"{{order.consignee|default(' ',True)}}");
        LODOP.ADD_PRINT_TEXT(294,202,147,16,"{{order.mobile_number|default(' ',True)}} {{order.phone_number|default(' ',True)}}");
        LODOP.ADD_PRINT_TEXT(294,470,152,16,"{{order.date_order|default(order.create_date,True)|strftime('%Y-%m-%d')}}");
        LODOP.ADD_PRINT_TEXT(317,105,490,16,"{{ order.city_id.city_name|default('', True) }}{{ order.county_id.county_name|default('', True) }}{{order.street|default('',True)}}");
        LODOP.ADD_PRINT_TEXT(317,470,100,16,"{{order.expected_delivery_time|default('',True)}} {{ order.expected_delivery_hour }}");
        LODOP.ADD_PRINT_TEXT(18,550,120,15,"第{{ loop.index//10+1 }}页/共{{order.order_line|length//10+1}} 页");
        {% if not options.priceHide %}
            {% if (order.amount_total|string|reverse)|length>=8 %}
            LODOP.ADD_PRINT_TEXT(593,88,22,16,"{{chinese[(order.amount_total|string|reverse)[8]]}}");
            {% endif %}
            {% if (order.amount_total|string|reverse)|length>=7 %}
            LODOP.ADD_PRINT_TEXT(592,125,18,16,"{{chinese[(order.amount_total|string|reverse)[7]]}}");
            {% endif %}
            {% if (order.amount_total|string|reverse)|length>=6 %}
            LODOP.ADD_PRINT_TEXT(592,159,18,16,"{{chinese[(order.amount_total|string|reverse)[6]]}}");
            {% endif %}
            {% if (order.amount_total|string|reverse)|length>=5%}
            LODOP.ADD_PRINT_TEXT(592,193,19,16,"{{chinese[(order.amount_total|string|reverse)[5]]}}");
            {% endif %}
            {% if (order.amount_total|string|reverse)|length>=4 %}
            LODOP.ADD_PRINT_TEXT(592,226,16,20,"{{chinese[(order.amount_total|string|reverse)[4]]}}");
            {% endif %}
            {% if (order.amount_total|string|reverse)|length>=3 %}
            LODOP.ADD_PRINT_TEXT(592,260,22,16,"{{chinese[(order.amount_total|string|reverse)[3]]}}");
             {% endif %}
            LODOP.ADD_PRINT_TEXT(592,298,18,16,"{{chinese[(order.amount_total|string|reverse)[2]]}}");
            LODOP.ADD_PRINT_TEXT(592,332,21,16,"{{chinese[(order.amount_total|string|reverse)[0]]}}");
            LODOP.ADD_PRINT_TEXT(592,433,120,16,"{{order.amount_total|default('',True)}}");
            //LODOP.ADD_PRINT_TEXT(635,125,270,16,"{{order.phone_number|default(' ',True)}}");
            {% if order.payment_method=='现金' %}
            LODOP.ADD_PRINT_TEXT(615,168,21,16,"{{'√'|string}}");
            {% endif %}
            {% if order.payment_method=='支票' %}
            LODOP.ADD_PRINT_TEXT(615,268,16,20,"{{'√'|string}}");
            {% endif %}
            {% if order.payment_method=='转账' %}
            LODOP.ADD_PRINT_TEXT(615,385,19,16,"{{'√'|string}}");
            {% endif %}
        {% endif %}

    {% endif%}

    {% if official_invoice_map.get(False) or official_invoice_map.get(True) %}
        LODOP.ADD_PRINT_TEXT(635,67,478,16,"注：{% if official_invoice_map.get(False) %}开票 {{ official_invoice_map.get(False) }}张{% endif %} {% if official_invoice_map.get(True) %}开票 {{ official_invoice_map.get(True) }}张(W){% endif %}");
    {% endif %}
    LODOP.ADD_PRINT_TEXT(650,67,478,72,"{{order.note|default(' ',True)|replace('\n', '\\r\\n')}}");
    LODOP.ADD_PRINT_TEXT(868,56,58,16,"{{order.user_id.partner_id.name|default(' ',True)}}");
    //LODOP.ADD_PRINT_TEXT(739,57,478,72,"注：发票"); 移到备注上方
    //产品名称已经包含了产品编号,所以不需要打印产品编号
    LODOP.ADD_PRINT_TEXT({{loop.index0 %10 * 22.7+364| round}},21,300,16,"[{{order_line.product_id.default_code}}] {{order_line.product_id.name|default('',True)}}");
    //LODOP.ADD_PRINT_TEXT({{loop.index0 %10 * 22.7+364| round}},90,210,16,"{{order_line.name|default('',True)}}");
    LODOP.ADD_PRINT_TEXT({{loop.index0 %10 * 22.7+364| round}},270,65,16,"{{order_line.product_id.prod_model|default(' ', True)}} {{order_line.prod_spec|default(' ', True)|replace('\n', '\\r\\n')}} {{order_line.sale_note|default(' ', True)|replace('\n', '\\r\\n')}}");
    LODOP.ADD_PRINT_TEXT({{loop.index0 %10 * 22.7+364| round}},335,15,16,"{{order_line.product_id.uos_id.name|default(' ',True)}}");
    {% if not options.priceHide %}
    LODOP.ADD_PRINT_TEXT({{loop.index0 %10 * 22.7+364| round}},345,60,16,"{{order_line.price_unit |round(2)}}");
    {% endif %}
    LODOP.SET_PRINT_STYLEA(0,"Alignment",3);
    LODOP.ADD_PRINT_TEXT({{loop.index0 %10 * 22.7+364| round}},400,55,16,"{{order_line.product_uom_qty|round|int}}");
    LODOP.SET_PRINT_STYLEA(0,"Alignment",3);
    {% if not options.priceHide %}
    LODOP.ADD_PRINT_TEXT({{loop.index0 %10 * 22.7+364| round}},453,84,16,"{{order_line.price_unit*order_line.product_uom_qty|round(2)}}");
    {% endif %}
    LODOP.SET_PRINT_STYLEA(0,"Alignment",3);

{% endfor %}
//LODOP.ADD_PRINT_TEXT(564,62,80,16,"产品编号10");


            LODOP.SET_PRINT_STYLEA(1, "Horient", 3);
        //}

    };

        </script>

    {% if options.priceHide %}
        <a href="?options={&quot;priceHide&quot;:0}" class="btn btn-primary">显示价格</a>
    {% else %}
        <a href="?options={&quot;priceHide&quot;:1}" class="btn btn-primary">隐藏价格</a>
    {% endif %}
        <a id="btn-print" href="javascript:print_preview()" class="btn btn-primary">联单直接打印</a>
        注: 点击按钮打印出库联单，打印A4纸按Ctrl+P键，或者菜单上面选择文件->打印，文件->页面设置里面可以去除页眉页脚

    </div>

<div id="div-header">
    <table border="0" cellSpacing="0" cellPadding="0" width="100%">
        <tbody>
            <tr>
                <td colspan="3" align="center">
                    <h4 class="page_head">
                        {%  if is_vip %}
                        VIP
                        {% endif %}
                        {% if have_fake_order or is_fake_order %} （必须本人签收） {% endif %}
                        {% if order.is_return %}
                            销售订单 退货单
                        {% elif order.real_so_id %}
                            销售订单F 出货单
                        {% else %}
                            {% if order.is_exchange %}
                                换货单
                            {% else %}

                                {% if order.state in ['draft','sent'] %}报价单{% else %}销售订单{% endif %}
                            {% endif %}
                            出货理货单
                        {% endif %}
                    </h4>
                </td>
            </tr>
            <tr>
                <td width="40%">客户:
                    {% if order.partner_id.is_company %}
                        {{ order.partner_id.name|default('', True) }}
                    {% else %}
                        {{ order.partner_id.name|default('', True) }}{{ order.partner_id.parent_id.name|default('', True) }}
                    {% endif %}

                </td>
                <td width="33%">联系人:
                     {{ order.consignee}}
                </td>
                <td><h5>编号:
                {% if order.real_so_id %}
                {{ order.real_so_id.name }}
                {% else %}
                 {{ order.name }}
                {% endif%}
                </h5></td>
            </tr>
            <tr>
                <td width="40%">地址:
                    {{ order.city_id.city_name|default('', True) }}
                    {{ order.county_id.county_name|default('', True) }}
                    {{ order.street|default('', True) }}
                    {% if order.freight_type == 'freight_collect' %}
                    (运费到付)
                    {% endif %}
                    {% if order.customer_pick_up %}
                    (客户自提)
                    {% endif %}
                </td>
                <td width="33%"><!--
                    手机: {{ order.partner_shipping_id.mobile|default('　　　　　　', True) }}
                    电话: {{ order.partner_shipping_id.phone|default('　　　　　　', True) }}-->
                </td>
                <td>　　下单日期: {{ order.date_order|default(order.create_date,True)|strftime('%Y-%m-%d') }}
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    {% if order.zip %}
                    邮编:{{ order.zip|default('', True) }}
                    {% endif %}
                </td>
                <td>
                    {% if order.is_return %}
                    预计退货时间:
                    {% else %}
                    预计发货时间:
                    {% endif %}
                    {% if order.expected_delivery_time %}
                        {{ order.expected_delivery_time }} {{ order.expected_delivery_hour }}
                    {% else %}
                        未指定
                    {% endif %}
                </td>
            </tr>
        </tbody>
    </table>
</div>


<div id="div-body">
    <table class="table table-striped" width="100%">
        <thead>
            <tr>
                <td width="15">#</td>
                <td>产品名称</td>
                <td>型号</td>
                <td>规格</td>
                <td>产品备注</td>
                {% if not options.priceHide %}
                <td class="nowrap" style="text-align: right;">单价</td>
                {% endif %}
                <td class="nowrap" style="text-align: right;">数量</td>
                {% if not options.priceHide %}
                <td class="nowrap" style="text-align: right;">小计</td>
                {% endif %}
            </tr>
        </thead>
        <tbody>
            {% for line in order.order_line %}
            <tr>
                <td>{{loop.index}}</td>
                <td>
                        <span>[{{ line.product_id.default_code}}]{{ line.product_id.name}}</span>
                </td>
                <td>{{line.prod_model|default("", True)}}</td>
                <td>{{line.product_id.prod_spec|default("", True)}}</td>
                <td>{{line.prod_spec|default("", True)}}{{line.sale_note|default("", True)}}</td>
                {% if not options.priceHide %}
                <td style="text-align: right;">{{ line.price_unit }}</td>
                {% endif %}
                <td style="text-align: right;">{{ line.product_uom_qty|int() }} {% if line.product_uos %}({{ line.product_uos.name }}){% endif %}</td>
                {% if not options.priceHide %}
                <td style="text-align: right;">￥{{ line.price_unit * line.product_uom_qty }}</td>
                {% endif %}
            </tr>
				{% for order_card in order.sale_order_id %}
						{% if order_card.product_id.id==line.product_id.id %}
						<tr>
							<td></td>
							<td style="text-align: left;" colspan="7">
							券号:{{order_card.starting_number.code}}{% if order_card.continue_number!=1 %}~{{order_card.ending_number}}({{order_card.continue_number}}张){% else %} ({{order_card.continue_number}}张){% endif %}
							</td>
						</tr>
						{% endif %}
				{% endfor %}
            {% endfor %}
            <tr>
                <td colspan="9" style="text-align: right;border-top: 1px solid #ddd;">
                    {% if not options.priceHide %}
                    合计：￥<span id="spanGrandTotal">{{ order.amount_total }}</span>
                    {% endif %}
                </td>
            </tr>
            <tr>
                <td colspan="8" style="text-align: left;border-top: 1px solid #ddd;">
                   备注：
                </td>
            </tr>
            {% if official_invoice_map.get(False) or official_invoice_map.get(True) %}
            <tr><td colspan="8">
                {% if official_invoice_map.get(False) %}开票:{{official_invoice_map.get(False)}}张{% endif %}
                {% if official_invoice_map.get(True) %}开票:{{official_invoice_map.get(True)}}张(W){% endif %}
            </td></tr>
            {% endif %}
            {% if order.note %}
                {% for line in order.note.split('\n') %}
                <tr class="memo">
                    <td colspan="8">
                        {{ line }}
                    </td>
                </tr>
                {% endfor %}
            {% endif %}
        </tbody>
    </table>
</div>


<div id="div-foot">
    业务：<span class="foot_sign">{{ order.user_id.name|default("　　　　") }}　　</span>
    主管:<span class="foot_sign">　　　　　　</span>
    财务：<span class="foot_sign">　　　　　　</span>
    采购：<span class="foot_sign">　　　　　　</span>
    仓库：<span class="foot_sign">　　　　　　</span>
</div>

    {%elif ids|length > 1 %}
        <a id="btn-batch-print" href="javascript:batch_print_next()" class="btn btn-primary">开始批量联单打印</a>
        注: 一共{{ids|length}}单，请把联单纸装好<br />
        <iframe id="single_print_iframe"
                width="100%" height="400px" style="margin-top:10px;border: 1px solid;" scrollin="yes"></iframe>
    <script language="javascript">
        var ids = {{ids}};
        var current_ids_index = 0;

//        function isIe(){
//            return window.ActiveXObject ? true : false;
//        }
//        function iframe_onload(){
//            //alert('iframe onload');
//            var single_print_iframe = document.getElementById('single_print_iframe');
//            window.current_ids_index ++;
//        }
//        window.onload = function(){
//            var single_print_iframe = document.getElementById('single_print_iframe');
//            if ( isIe() ) {
//                single_print_iframe.attachEvent( "onload", iframe_onload );
//            } else {
//                single_print_iframe.onload = iframe_onload;
//            }
//        }

        function batch_print_next(){
            document.getElementById('btn-batch-print').innerHTML = "正在打印第" + (window.current_ids_index + 1) + "单";
            document.getElementById('btn-batch-print').className = "btn btn-primary disabled";
            if (window.current_ids_index < ids.length){
                var single_print_iframe = document.getElementById('single_print_iframe');
                var url = window.location.href;
                right_pos = url.lastIndexOf('/');
                url = url.substring(0, right_pos + 1);
                var order_id = ids[current_ids_index];
                //alert(order_id);
                single_print_iframe.src = url + order_id;
                window.current_ids_index ++;
            }
            else{
                document.getElementById('btn-batch-print').innerHTML = "已经全部打印完毕";
                document.getElementById('btn-batch-print').className = "btn btn-primary disabled";
            }
        }
    </script>
    {%endif%}
    </body>
</html>
